package com.itheima.d1_create_thread.ZengTest2;

/**
 * @ClassName zengTest2
 * @Author 16799
 * @Date 2025/8/31 15:23
 * @Version 1.0
 * @Description TODO
 **/
public class zengTest2 {
    public static void main(String[] args) {
        zengRunnable zengRunnable = new zengRunnable();
        Thread zthread = new Thread(zengRunnable);

        zthread.start();

        System.out.println("------------创建线程方式简化一下，中间不再创建runnable任务对象-----");
        new Thread(new zengRunnable()).start();

        System.out.println("--------不再使用runnable实现类作为任务对象给thread创建线程，而是匿名内部类--------");
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 5; i++) {
                    System.out.println("我是匿名内部类，实现runnable接口然后创建线程");
                }
            }
        }).start();

        System.out.println("------匿名内部类形式再简化，用lambda表达式----");
        new Thread(()->{
            for (int i = 0; i < 5; i++) {
                System.out.println("runnable接口的lambda表达式写法创建线程");
            }
        }).start();

        for (int i = 0; i < 4; i++) {
            System.out.println("主线程： "+i);
        }
    }
}
